import { WereWolfTimeLimiter } from "@/werewolf/components/timeLimiter";
import { WereWolfWolfDaemon } from "@/werewolf/components/wolfDaemon";
import { WereWolfModule } from "@/werewolf/module";
import { WereWolfRole } from "@/werewolf/player";
import { Timer } from "@sapi-game/gameComponent/common/timer/timer";

export class WereWolfWolfPhase extends WereWolfModule.State {
    override onEnter(): void {
        this.addComponent(Timer, { initialTime: 120 }).addComponent(
            WereWolfTimeLimiter,
            {
                getPlayers: () => this.getWolves(),
                onEnd: () => this.next(),
            }
        );
        this.addComponents(this.context.map.phaseViews.wolf);
    }

    /**开始计时等 */
    startPhase() {
        this.addComponent(WereWolfWolfDaemon);
        this.getComponent(Timer).start();
    }

    getWolves() {
        return this.context.players.filter(
            (p) => !p.dead && p.role == WereWolfRole.Werewolf
        );
    }

    next() {
        this.getWolves().forEach((p) => p.title("请立即回家"));
        this.popState();
    }
}
